package com.fastloan.jn.mgt.customer.controller;

import com.fastloan.jn.mgt.customer.model.JnCustomerMaintenance;
import com.fastloan.jn.mgt.customer.service.JnCustomerMaintenanceService;
import com.fastloan.safe.core.util.ManagerKit;
import com.kawins.base.baseabs.BaseController;
import com.kawins.result.ResultEnum;
import com.kawins.result.ResultTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author chenkai
 *         createTime 2017-10-2017/10/19 15:37
 */
@RestController
@RequestMapping("/api/web/customerMaintenance")
public class JnCustomerMaintenanceController extends BaseController<JnCustomerMaintenance> {

    @Autowired
    private JnCustomerMaintenanceService customerMaintenanceService;

    @RequestMapping("/{customerId}/pageList")
    public ResultTo pageList(@PathVariable String customerId) {
        Map<String, Object> map = new HashMap<>(1);
        map.put("customerId", customerId);
        return dataPage(map);
    }

    /**
     * 获取维护信息信息
     *
     * @param bankId
     * @return
     */
    @GetMapping("/{bankId}")
    public ResultTo getBank(@PathVariable String bankId) {
        return new ResultTo().setData(customerMaintenanceService.selectByPrimaryKey(bankId));
    }

    /**
     * 新增维护信息信息
     *
     * @param customerMaintenance
     * @return
     */
    @PostMapping
    public ResultTo add(JnCustomerMaintenance customerMaintenance) {
        customerMaintenance.setCreateTime(new Date());
        customerMaintenance.setCreateBy(ManagerKit.getUserId());
        return customerMaintenanceService.insertSelective(customerMaintenance) != 0 ? new ResultTo() : new ResultTo(ResultEnum.OPERATION_FAILED);
    }

    /**
     * 更新维护信息信息
     *
     * @param customerMaintenance
     * @return
     */
    @PutMapping
    public ResultTo update(JnCustomerMaintenance customerMaintenance) {
        return customerMaintenanceService.updateByPrimaryKeySelective(customerMaintenance) != 0 ? new ResultTo() : new ResultTo(ResultEnum.OPERATION_FAILED);
    }

}
